﻿using CastingWellEquipmentGUI.Model;
using CastingWellEquipmentGUI.ViewModel.Modal;
using CastingWellEquipmentGUI.ViewModel.Modal.CalendarWindow;
using CastingWellEquipmentGUI.ViewModel.Modal.CastWellPublic;
using CastingWellEquipmentGUI.ViewModel.Modal.CastWellPublicAuxiliary;
using CastingWellEquipmentGUI.ViewModel.Modal.DrainageSystem;
using CastingWellEquipmentGUI.ViewModel.Modal.Launde;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CastingWellEquipmentGUI.ViewModel.Common.WindowsManager
{
    /// <summary>
    /// 窗口管理器
    /// </summary>
    public static class WindowManager
    {
        private static Hashtable _RegisterWindow = new Hashtable();
        public static void Register<T>(string key)
        {
            if (!_RegisterWindow.Contains(key))
            {
                _RegisterWindow.Add(key, typeof(T));
            }
        }



        public static void Register(string key, Type t)
        {
            if (!_RegisterWindow.Contains(key))
            {
                _RegisterWindow.Add(key, t);
            }
        }

        public static void Remove(string key)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                _RegisterWindow.Remove(key);
            }
        }

        /// <summary>
        /// 普通打开
        /// </summary>
        /// <param name="key"></param>
        /// <param name="VM"></param>
        public static void Show(string key, object VM)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                win.Show();
            }
        }

        /// <summary>
        /// 启动Or关闭按钮
        /// </summary>
        /// <param name="key">窗体Key</param>
        /// <param name="CallbackFuncationName">提供给调用者用来设置回调消息名称</param>
        public static void ShowModalOnOrOffPanel(string key, string CallbackFuncationName)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                var OnOrOffPanel = (OnOrOffPanelViewModel)win.DataContext;
                OnOrOffPanel.SetCallbackFuncationName(CallbackFuncationName);
                win.ShowDialog();
            }
        }

        /// <summary>
        /// 测试Or启动Or关闭按钮
        /// </summary>
        /// <param name="key">窗体Key</param>
        /// <param name="CallbackFuncationName">提供给调用者用来设置回调消息名称</param>
        public static void ShowModalTestOrOnOrOffPanel(string key, string CallbackFuncationName)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                var OnOrOffPanel = (TestOrOnOrOffPanelViewModel)win.DataContext;
                OnOrOffPanel.SetCallbackFuncationName(CallbackFuncationName);
                win.ShowDialog();
            }
        }

        /// <summary>
        /// 自动Or手动
        /// </summary>
        /// <param name="key">窗体Key</param>
        /// <param name="CallbackFuncationName">提供给调用者用来设置回调消息名称</param>
        public static void ShowModalHandOrAutoPanel(string key, string CallbackFuncationName)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                var HandOrOAutoPanel = (HandOrAutoPanelViewModel)win.DataContext;
                HandOrOAutoPanel.SetCallbackFuncationName(CallbackFuncationName);
                win.ShowDialog();
            }
        }

        /// <summary>
        /// 模态窗口打开
        /// </summary>
        /// <param name="key"></param>
        /// <param name="VM"></param>
        public static void ShowDialog(string key, object VM)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                win.ShowDialog();
            }
        }

        public static void ShowModalDigitalInputPanel(string key, string CallbackFuncationName, string currentVal)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                var setCVPanel = (SetCVPanelViewModel)win.DataContext;
                setCVPanel.SetCallbackFuncationName(CallbackFuncationName);
                setCVPanel.SetCurrentVal(currentVal);
                win.ShowDialog();
            }
        }
        /// <summary>
        /// 启动Or关闭按钮
        /// </summary>
        /// <param name="key">窗体Key</param>
        /// <param name="CallbackFuncationName">提供给调用者用来设置回调消息名称</param>
        public static void ShowModalOnOrOfffAndZhuOrFuPanel(string key, string CallbackFuncationName)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                var OnOrOffAndZhuOrFuPanel = (OnOrOffAndZhuOrFuPanelWindowViewModel)win.DataContext;
                OnOrOffAndZhuOrFuPanel.SetCallbackFuncationName(CallbackFuncationName);
                win.ShowDialog();
            }
        }
        public static void ShowModalCalendar(string key, string param)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                var calendarWindow = (CalendarWindowViewModel)win.DataContext;
                calendarWindow.SetSource(param);
                win.ShowDialog();
            }
        }

        ///// <summary>
        ///// 模态窗口打开确认框
        ///// </summary>
        ///// <param name="key">要打开的窗体</param>
        ///// <param name="title">提示标题</param>
        ///// <param name="content">提示内容</param>
        ///// <param name="CallbackMessage">回调信息</param>
        //public static void ConfirmShow(string title, string content, string CallbackMessage)
        //{
        //    string key = "ConfirmWindow";
        //    if (_RegisterWindow.ContainsKey(key))
        //    {
        //        ConfirmWindow win = (ConfirmWindow)Activator.CreateInstance((Type)_RegisterWindow[key]);
        //        win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        //        ConfirmViewModel confirmWindowModelView = (ConfirmViewModel)win.DataContext;
        //        confirmWindowModelView.Title = title;
        //        confirmWindowModelView.Content = content;
        //        confirmWindowModelView.CallbackMessage = CallbackMessage;
        //        win.ShowDialog();
        //    }
        //}

        ///// <summary>
        ///// 模态窗口打开确认框
        ///// </summary>
        ///// <param name="key">要打开的窗体</param>
        ///// <param name="title">提示标题</param>
        ///// <param name="content">提示内容</param>
        ///// <param name="CallbackMessage">回调信息</param>
        //public static void ShowWarning(string title, string content)
        //{
        //    string key = "WarningWindow";
        //    if (_RegisterWindow.ContainsKey(key))
        //    {
        //        WarningWindow win = (WarningWindow)Activator.CreateInstance((Type)_RegisterWindow[key]);
        //        win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        //        WarningViewModel warningWindowViewModel = (WarningViewModel)win.DataContext;
        //        warningWindowViewModel.Title = title;
        //        warningWindowViewModel.Content = content;
        //        win.ShowDialog();
        //    }
        //}

        /// <summary>
        /// 模态窗口打开编辑用户窗体
        /// </summary>
        /// <param name="key"></param>
        /// <param name="VM"></param>
        public static void ShowModalPanel(string key, object framName, object controlName)
        {
            if (_RegisterWindow.ContainsKey(key))
            {
                var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
                win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                if (key.ToString() == "LaunderBafflePanel")
                {
                    var launderBafflePanel = (LaunderBafflePanelViewModel)win.DataContext;
                    launderBafflePanel.LoadTagInfoByFramNameAndControlName(framName, controlName);
                }
                else if (key.ToString() == "AuroraLevelGaugePanel")
                {
                    var auroraLevelGaugePanel = (AuroraLevelGaugePanelViewModel)win.DataContext;
                    auroraLevelGaugePanel.LoadTagInfoByFramNameAndControlName(framName, controlName);
                }
                win.ShowDialog();
            }
        }
        ///// <summary>
        ///// 模态窗口打开编辑程序块值的窗体
        ///// </summary>
        ///// <param name="key"></param>
        ///// <param name="VM"></param>
        //public static void ShowEditValue(string key, TagInfo param)
        //{
        //    if (_RegisterWindow.ContainsKey(key))
        //    {
        //        var win = (Window)Activator.CreateInstance((Type)_RegisterWindow[key]);
        //        win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
        //        EditValueWindowViewModel tagInfoEdit = (EditValueWindowViewModel)win.DataContext;
        //        tagInfoEdit.LoadTagInfo(param);
        //        win.ShowDialog();
        //    }
        //}


    }
}
